/*
 * @Author: your name
 * @Date: 2020-08-13 19:35:31
 * @LastEditTime: 2020-08-13 19:56:16
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \day01\demo11\main.go
 */
package main

import (
	"fmt"
	"net/http"
	"text/template"
)

func sayHello(w http.ResponseWriter, r *http.Request) {
	tmpl, err := template.ParseFiles("./hello.tmpl")
	if err != nil {
		fmt.Println("failed", err)
		return
	}
	tmpl.Execute(w, "哈哈,我是你爸爸")
}

type UserInfo struct {
	Name   string
	Gender string
	Age    int
}

func sayHelloStruct(w http.ResponseWriter, r *http.Request) {
	tmpl, err := template.ParseFiles("./hellostruct.tmpl")
	if err != nil {
		fmt.Println("failed", err)
		return
	}
	user := UserInfo{
		Name:   "张三",
		Gender: "男",
		Age:    19,
	}
	tmpl.Execute(w, user)

}

func main() {
	http.HandleFunc("/", sayHello)
	http.HandleFunc("/hello", sayHelloStruct)

	err := http.ListenAndServe(":9999", nil)
	if err != nil {
		fmt.Println("err", err)
		return
	}
}

// 更多MVT的介绍请查看官网，这里不做多的介绍，一般用的较多的都是MVC
